//
//  YMMineTopInforAndDeviceCell.swift
//  YMMedical
//
//  Created by y s on 2023/7/25.
//

import UIKit

typealias TapClickBlock = () -> ()

@objcMembers class YMMineTopInforAndDeviceCell: UITableViewCell {

    lazy var vBg: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "mine_top_bg_icon")
        result.isUserInteractionEnabled = true
        return result
    }()
    lazy var imgvLogo: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "mine_user_default_logo")
        result.clipsToBounds = true
        result.layer.cornerRadius = SFitUtil.fit(30)
        result.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(headTapClickAction))
        result.addGestureRecognizer(tap)
        return result
    }()
    lazy var lblTitle: UILabel = {
        let result = SThemeUtil.boldLabel("未登录", color: STheme.H_D9, fontSize: 16)
        return result
    }()
    lazy var btnSet: UIButton = {
        let result = UIButton(type: .custom)
        result.setImage(UIImage(named: "mine_icon_shezhi"), for: .normal)
        result.addTarget(self, action: #selector(setClickAction(_:)), for: .touchUpInside)
        return result
    }()
    lazy var vItem: YMMineTabListItemView = {
        let result = YMMineTabListItemView()
        return result
    }()
    
    public var tapClickBlock: TapClickBlock?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUI()
    }
    
    
    // MARK: UI
    func setUI() {
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        selectionStyle = .none
        
        contentView.addSubview(vBg)
        vBg.addSubview(lblTitle)
        vBg.addSubview(imgvLogo)
        vBg.addSubview(btnSet)
        contentView.addSubview(vItem)
        
        vBg.snp.makeConstraints { make in
            make.top.left.right.bottom.equalTo(0)
            make.bottom.equalTo(SFitUtil.fit(-43))
        }
        imgvLogo.snp.makeConstraints { make in
            make.top.equalTo(SFitUtil.statusBarHeight+SFitUtil.fit(30))
            make.left.equalTo(SFitUtil.fit(15))
            make.size.equalTo(SFitUtil.fitSize(60, height: 60))
        }
        lblTitle.snp.makeConstraints { make in
            make.centerY.equalTo(imgvLogo)
            make.left.equalTo(imgvLogo.snp.right).offset(SFitUtil.fit(15))
            make.right.equalTo(btnSet.snp.left)
        }
        btnSet.snp.makeConstraints { make in
            make.right.equalTo(0)
            make.centerY.equalTo(imgvLogo)
            make.size.equalTo(SFitUtil.fitSize(54, height: 54))
        }
        vItem.snp.makeConstraints { make in
            make.left.equalTo(SFitUtil.fit(15))
            make.right.equalTo(SFitUtil.fit(-15))
            make.bottom.equalTo(0)
            make.height.equalTo(SFitUtil.fit(64))
        }
        updataLanguage()
    }
    
    public func updateData(_ userName: String){
        self.lblTitle.text = userName
        updataLanguage()
    }
    public class func getCellHeight() -> CGFloat {
        return SFitUtil.fit(43+116+15)+SFitUtil.statusBarHeight
    }
    
    private func updataLanguage(){
        let dict: Dictionary<String, Any> = ["title":YMBridging.kLanguage("my_device_txt"), "icon":"mine_icon_shebei", "type":1]
        vItem.changeData(dict)
    }

    func setClickAction(_ sender: UIButton) {
       let vc = YMSettingViewController()
        vc.hidesBottomBarWhenPushed = true
        SJumpUtil.pushVC(vc,animated: true)
    }
    
    func headTapClickAction() {
        if tapClickBlock != nil {
            tapClickBlock!()
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
